package com.sxt.server.handler;

import com.sxt.server.common.model.TranslatorData;
import com.sxt.server.common.model.TranslatorDataWapper;

import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
/**
 * 	抽象消费者的实现类
 * @author Administrator
 *
 */
@Slf4j
public class MessageConsumerImpl extends MessageConsumer {

	public MessageConsumerImpl(String consumerId) {
		super(consumerId);
	}

	@Override
	public void onEvent(TranslatorDataWapper event, long sequence, boolean endOfBatch) throws Exception {
		TranslatorData request = event.getData();
        ChannelHandlerContext ctx = event.getCtx();
        //1.业务处理逻辑:
        log.info("Sever端: id= " + request.getId()
        + ", name= " + request.getName()
        + ", message= " + request.getMessage());
         
        //2.回送响应信息:
        TranslatorData response = new TranslatorData();
        response.setId("resp: " + request.getId());
        response.setName("resp: " + request.getName());
        //response.setMessage("resp: " + request.getMessage());
        //写出response响应信息:
        ctx.writeAndFlush(response);
	}

	@Override
	public void onEvent(TranslatorDataWapper event) throws Exception {
		onEvent(event);
	}

}
